#include "Player.h"
#include "Renderer.h"
#include <new>
Player::Player(long long id, int x, int y)
{
	m_objectType = OBJECT_TYPE::PLAYER;
	m_objectID = id;
	Position& pos = GetPosition();
	pos.x = x;
	pos.y = y;
	pos.height = 20;
	pos.width = 20;
	m_speed = 3;
	m_keyState = KEY_STATE::IDLE;

}
Player::~Player(void)
{

}
void Player::DestroyData(void)
{

}
void Player::Copy(void* address)
{
	new (address) Player(*this);
}
void Player::Update(void)
{
	Position& pos = GetPosition();
	if (m_keyState == KEY_STATE::LEFT_PRESSED)
	{
		if (pos.x <= m_speed)
			return;
		pos.x -= m_speed;
	}
	else if (m_keyState == KEY_STATE::RIGHT_PRESSED)
	{
		if (pos.x >= SCREEN_WIDTH - pos.width)
			return;
		pos.x += m_speed;
	}
}
void Player::Draw(void)
{
	Renderer::GetInstance().DrawObject(*this);
}
int Player::GetObjSize(void)
{
	return sizeof(*this);
}
SDL_Texture* Player::GetTexture(void)
{
	static SDL_Texture* texture = 0;
	if (!texture)
	{
		texture = Renderer::GetInstance().LoadTexture("c:/test.bmp");
	}
	return texture;
}
void Player::SetKeyState(KEY_STATE keyState)
{
	m_keyState = keyState;
}
KEY_STATE Player::GetKeyState(void)
{
	return m_keyState;
}